<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>我的信息</title>
    <!--引入 bootstrap 弹窗的样式 -->
    <link rel="stylesheet" href="/bootstrap/css/bootstrap.min.css">
    <!--引入 Layer 弹窗的样式 -->
    <link rel="stylesheet" href="/layer/theme/default/layer.css"/>
    <!--引入 angularJS 分页的样式 -->
    <link rel="stylesheet" href="/angularjs/pagination.css">
    <!--引入 jquery 类库 -->
    <script src="/bootstrap/js/jquery.min.js"></script>
    <!--引入 bootstrap 类库 -->
    <script src="/bootstrap/js/bootstrap.min.js"></script>
    <!--引入 angular 的类库 -->
    <script src="/angularjs/angular.min.js"></script>
    <!--引入 Layer 弹窗的类库 -->
    <script src="/layer/layer.js"></script>
    <!--引入 angularJS 框架分页的类库 -->
    <script src="/angularjs/pagination.js"></script>
</head>
<body ng-app="app" ng-controller="ctr" ng-init="loaduser()">
<div class="container">
    <div class="panel panel-default">
        <nav class="navbar navbar-default" role="navigation">
            <div class="container-fluid">
                <div class="navbar-header">
                    <a class="navbar-brand">我的信息</a>
                </div>
                <ul class="nav navbar-nav navbar-right">
                    <li><a href="#" ng-click="toStock()"><span class="glyphicon glyphicon-home"></span> 行情首页</a></li>
                </ul>
            </div>
        </nav>
        <div class="panel-body">
            <div style="height: 60px;width: 100%" >
                <ul class="nav navbar-nav">
                    <li><a href="#" ng-click="showThis(true)" > 个人信息</a></li>
                    <li><a href="#" ng-click="showThis(false)"> 实名认证</a></li>
                </ul>
            </div>
            <div ng-hide="isShow" style="height: 300px;width: 100%;padding-top: 50px;">
                <form class="form-horizontal" role="form">
                <div class="form-group">
                    <label  class="col-md-offset-1 col-md-2 control-label">账号：</label>
                    <div class="col-md-4">
                        <input type="hidden" class="form-control" ng-model="user.userId" >
                        <input type="text" class="form-control" ng-model="user.userName" >
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-offset-1 col-md-2 control-label">手机号：</label>
                    <div class="col-md-4">
                        <input type="text" class="form-control" ng-model="user.phone" >
                    </div>
                </div>
                <div class="form-group">
                    <label  class="col-md-offset-1 col-md-2 control-label">真实姓名：</label>
                    <div class="col-md-4">
                        <input type="text" class="form-control" ng-model="user.userTname" >
                    </div>
                    <div class="col-md-4" ng-if="user.userState==1">
                        <span class="glyphicon glyphicon-saved" style="color: green">已认证</span>
                    </div>
                    <div class="col-md-4" ng-if="user.userState==0">
                        <span class="glyphicon glyphicon-remove" style="color: red">未认证</span>
                    </div>
                </div>
                <div class="form-group">
                    <label  class="col-md-offset-1 col-md-2 control-label">身份证号码：</label>
                    <div class="col-md-4">
                        <input type="text" class="form-control" ng-model="user.userCard" >
                    </div>
                    <div class="col-md-4" ng-if="user.userState==1">
                        <span class="glyphicon glyphicon-saved" style="color: green">已认证</span>
                    </div>
                    <div class="col-md-4" ng-if="user.userState==0">
                        <span class="glyphicon glyphicon-remove" style="color: red">未认证</span>
                    </div>
                </div>
                    <div class="form-group">
                        <div class="col-sm-offset-3 col-sm-2">
                            <button type="button" ng-click="submit()" class="btn btn-primary btn-block">提交</button>
                        </div>
                    </div>
                </form>
            </div>
            <div ng-show="isShow">
                <div class="row" style="margin-bottom: 20px">
                    <div class=" col-md-2" style="font-size: 18px">余额: <sapn style="color: blue">{{user.userMoney | number:2}}</sapn></div>
                    <div class="col-md-offset-2 col-md-2">
                        <button class="btn btn-warning btn-block" ng-click="updateMoney(0)">充值</button>
                    </div>
                    <div class="col-md-2">
                        <button class="btn btn-warning btn-block" ng-click="updateMoney(1)">提现</button>
                    </div>
                    <div class="col-md-2">
                        <button class="btn btn-success btn-block" ng-click="record()">记录</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="panel-footer">
            <span>{{time|date:'yyyy-MM-dd HH:mm:ss'}}</span>
            <span style="float: right">&copy; 2021 SEA 版权所有</span>
        </div>
    </div>
</div>
<!-- 充值框 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">充值提现</h4>
            </div>
            <div class="modal-body">
                <form class="form form-horizontal">
                    <div class="form-group">
                        <label  class="control-label col-md-3">金额</label>
                        <div class=" col-md-5 ">
                            <input class="form-control" ng-model="moneyType" type="hidden">
                            <input id="money" class="form-control" ng-model="money" placeholder="请输入金额">
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-warning" ng-click="confirm()">确定</button>
            </div>
        </div>
    </div>
</div>
<script>
    angular.module("app", ['ngCookies', 'pagination']).config(function ($httpProvider) {
        $httpProvider.defaults.useXDomain = true;
        delete $httpProvider.defaults.headers.common['X-Requested-With']
    })
    .controller("ctr", ["$scope", "$http", '$interval', '$timeout', function ($scope, $http, $interval, $timeout) {
        $scope.time = new Date(); //日期时间信息
        $scope.isShow = true;

        //显示日期时间
        $interval(function () {
            $scope.time = new Date();
        }, 1000);

        //查看行情首页
        $scope.toStock = function () {
            window.location.href = "/views/stock/list.html";
        };

        //展示切换
        $scope.showThis = function(isShow){
            $scope.isShow = isShow;
        };

        //查看我的信息
        $scope.loaduser = function () {
            $http.get("http://localhost:12000/user/loaduser",{headers: {token: localStorage.getItem("token")}}).success(function (data) {
                if (data.code == 200) {
                    $scope.user=data.data;
                }
                if(data.code == 403){
                    window.location.href="/views/user/login.html";
                }
            });
        };

        //用户身份证认证
        $scope.submit = function () {
            $http.post("http://localhost:12000/user/identity",$scope.user,{headers: {token: localStorage.getItem("token")}}).success(function (data) {
                if (data.code == 200) {
                    //重新设置token
                    localStorage.setItem("token",data.data);
                    layer.msg(data.msg, {icon: 6});
                }
                if (data.code == 400) {
                    layer.msg(data.msg, {icon: 5});
                }
                if(data.code == 403){
                    window.location.href="/views/user/login.html";
                }
                $scope.loaduser();
            });
        };

        //打开充值框
        $scope.updateMoney = function (i) {
            //验证用户是否实名认证
            $http.get("http://localhost:12000/user/checkCard", {headers: {token: localStorage.getItem("token")}}).success(function (data) {
                if (data.code == 200) {
                    $scope.moneyType = i;
                    $scope.money = "";
                    $('#myModal').modal('show');
                }
                if (data.code == 403) {
                    window.location.href = "/views/user/login.html";
                }
                if (data.code == 401) {
                    layer.msg(data.msg, {icon: 5});
                }
            });
        };

        //提交充值提现
        $scope.confirm = function () {
            if ($scope.money <=0){
                layer.tips('请输入正确金额', '#money', {tips: [2, '#F92A2A']});
                return;
            }

            if ($scope.moneyType == 0){
                var money = $scope.money;
            }
            if ($scope.moneyType == 1){
                var money = 0-$scope.money;
            }

            $http.get("http://localhost:12000/user/alterMoney/"+money,{headers: {token: localStorage.getItem("token")}}).success(function (data) {
                if (data.code == 200) {
                    layer.msg(data.msg, {icon: 6});
                    $scope.loaduser();
                    $('#myModal').modal('hide');
                }
                if (data.code == 403) {
                    window.location.href = "/views/user/login.html";
                }
            });
        };

        //去充值提现记录页面
        $scope.record = function () {
            window.location.href = "/views/stock/moneyRecord.html"
        }

    }]);
</script>
</body>
</html>